<?php
namespace My\Controller;

use Utuo\BackgroundController;

class WechatActivityVoteController extends BackgroundController
{
    // init
    public function _initialize()
    {
        $this->setControllerTitle('微投票');
        $this->setActionTitle(array(
            'index' => '投票管理',
            'add' => '添加投票',
            'recycle' => '回收站',
            'modify' => '修改投票',
            'delete' => '删除投票'
        ));
        
        $this->setActionNav('index,add,recycle');
    }
    
    // getList
    public function getLists($is_deleted)
    {
        $page = $this->getPage();
        $pagesize = $this->getPageSize();
        $d = D('WechatActivityVote');
        $condition = array(
            'cid' => $this->aid,
            'is_deleted' => $is_deleted
        );
        $list = $d->where($condition)
            ->limit($pagesize)
            ->page($page)
            ->order('id DESC')
            ->select();
        $count = $d->where($condition)->count();
        foreach ($list as &$v) {
//             $v['activityUrl'] = $this->getUrl($this->aid, $v['id']);
//             http://294.z.wmfl.cn/index.php/Home/WechatVote/index/cid/294/aid/8.html
            $v['activityUrl'] = uu($this->aid,'Home','WechatVote','index',array('cid'=>$this->aid,'aid'=>$v['id']),true);
        }
        $this->assign('itemList', $list);
        $this->showPage($count, $pagesize);
        $this->display();
    }

    /*
     * 投票选项管理
     */
    public function optionAction()
    {
        $this->setActionTitle('option', '投票选项管理');
        $id = I('id', 0, 'intval');
        $m = M('WechatActivityVoteOption o');
        
        $lists = $m->select();
        $this->assign('optionLists', $lists);
        $this->display();
    }
    
    // 获取前台活动URL
    protected function getUrl($cid, $aid)
    {
        $url = uu($cid, 'Home', 'WechatVote', 'index', array(
            'cid' => $cid,
            'aid' => $aid
        ), true, true);
        return $url;
    }
}